package io.gitee.caoxiaoyu97;

import com.alibaba.excel.support.ExcelTypeEnum;
import io.gitee.caoxiaoyu97.entity.ExcelModelFieldDTO;
import io.gitee.caoxiaoyu97.excel.EasyExcelUtil;
import io.gitee.caoxiaoyu97.util.DynamicClassUtil;
import io.gitee.caoxiaoyu97.util.GroovyUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

/*********************************************************
 * 文件名称：${NAME}.java
 * 系统名称：${PROJECT_NAME}
 * 模块名称：io.gitee.caoxiaoyu97
 * 功能说明：${TODO}
 * 开发人员 @author：caoxy
 * 开发时间 @date：${DATE} ${TIME}
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
@Slf4j
public class Main {
    public static void main(String[] args) throws FileNotFoundException, NoSuchMethodException,
            InvocationTargetException, InstantiationException, IllegalAccessException {
        ArrayList<ExcelModelFieldDTO> excelModelFieldDTOS = new ArrayList<>();
        String[] strings = new String[10];
        for (int i = 0; i < 10; i++) {
            int finalI = i;
            excelModelFieldDTOS.add(new ExcelModelFieldDTO() {
                {
                    setModelId("excel" + finalI);
                    setFieldId("id" + finalI);
                    setFiledName("id啊" + finalI);
                    setFieldIndex("" + finalI);
                    setAnotations("@NumberFormat(\"#,##).00\")");
                    setImports("import com.alibaba.excel.annotation.format.NumberFormat;");
                }
            });
            strings[i] = "" + i;
        }
        String classJavaStr = DynamicClassUtil.getModelCode(excelModelFieldDTOS);
        Class clazz = GroovyUtil.parseClass(classJavaStr);
        String fileName = "aaa.xlsx";
        OutputStream outputStream = new FileOutputStream(fileName);
        Object o = EasyExcelUtil.convertExcelBO(fileName,strings ,
                clazz.getDeclaredConstructor().newInstance());
        EasyExcelUtil.writeExcelWithModel(outputStream,Arrays.asList(o),ExcelTypeEnum.XLSX,
                "测试报表",Arrays.asList("报表日期：" + new Date()));

    }

}